<!DOCTYPE html>
<html>
<head>
	<title>Meteoritos - preprocessamento do arquivo</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8" >
	<link rel="stylesheet" href="css/style.css" />
 <link rel="stylesheet" href="css/leaflet.css" />
 <link rel="stylesheet" href="css/dc.css" />
	<!--<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />-->
</head>

<body>
	<script type="text/javascript" src="js/d3.js"></script>
	<script type="text/javascript" src="js/OpenLayers.js"></script>
	<script type="text/javascript" src="data/countries.geo.js"></script>


<span id="file"></span>
	
	<script type="text/javascript">
				
		
		function setInvalidCoordinates(n, m) {
			if (n == "" | m == "") return true;
			return false;
		}
		
		function identifyCountry(lon, lat){
						
				if( setInvalidCoordinates(lon, lat) ){
						return 'Inválido';
				}
						
				
				var parser = new OpenLayers.Format.GeoJSON();
				var vectors = parser.read(countries);
				var point = new OpenLayers.Geometry.Point(lon, lat);
				for( var i = 0; i< vectors.length; i++ ){
				    if(vectors[i].geometry.intersects(point)){
				       return (vectors[i].attributes['name']);
				    }
				}
				
				return 'Caiu na água';
				
		}
		

		// lendo dados----------------------------------------------------
		
		d3.csv("data/meteoritestest.csv", function(data) {
    //var i = 0;
    var dataSet = data.map(function(d){
				  //console.log(i++, "     ", d.id);
				  document.getElementById('file').innerHTML += d.name + "," 
				  																																							+ d.nametype + "," 
				  																																							+ "\"" + d.recclass + "\"" + "," 
				  																																							+ d.mass + "," 
				  																																							+ d.fall + "," 
				  																																							+ d.year + "," 
				  																																							+ d.id + "," 
				  																																							+ d.reclat + "," 
				  																																							+ d.reclong + "," 
				  																																							+ identifyCountry(+d.reclong, +d.reclat) 
				  																																							+ "<br>";
  			});
  			
		});
  	

	</script>
</body>

</html> 